package leetcode.code0606;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

public class Solution implements IDebug {

	public String tree2str(TreeNode root) {
		StringBuffer sb = new StringBuffer();
		this.tree2str(root, sb);
		return sb.toString();
	}

	private void tree2str(TreeNode root, StringBuffer sb) {
		sb.append(root.val);
		if (root.left != null) {
			sb.append('(');
			this.tree2str(root.left, sb);
			sb.append(')');
		} else if (root.right != null) {
			sb.append('(').append(')');
		}
		if (root.right != null) {
			sb.append('(');
			this.tree2str(root.right, sb);
			sb.append(')');
		}
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
